import Vue from 'vue'
import VueRouter from 'vue-router'
import routes from './routes'

Vue.use(VueRouter)

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

router.beforeEach((to, from, next) => {
  // 判断是否登录
  const isLogin = localStorage.manageSystemToken

  if (to.path === '/login' || to.path === '/register') {
    next()
  } else {
    if (isLogin) {
      next()
    } else {
      next('/login')
    }
  }
})

export default router
